/**
 * XmlUtil.java
 * Product:BaseLayer
 * Version:1.0
 * Copyright 2009 by DNE
 * All Rights Reserved.
 */
package com.site.util;

import java.io.File;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * 动态管理XML文件
 * 
 */
public class XmlUtil {

	private Logger log = Logger.getLogger(XmlUtil.class);

	/**
	 * 读取xml文件
	 * 
	 * @param filepath
	 *            文件路径
	 * @return
	 */
	public Element getRootElement(String filepath) {
		Element root = null;
		try {
			SAXReader saxreader = new SAXReader();
			Document document = saxreader.read(new File(filepath));
			log.debug("读取资源文件:" + filepath);
			root = document.getRootElement();
			log.debug("读取资源文件结束");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			log.error("读取资源文件出错！", e);
			e.printStackTrace();
			return null;
		}

		return root;
	}

}
